package com.xju.subjectsystem.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * -*- coding:utf-8 -*-
 *
 * @projectName: Subjectsystem
 * @package: com.xju.subjectsystem.aop
 * @className: RecordTimeAspect
 * @author: Eiard
 * @description: DONE : 计算方法执行时间的切面
 * @date: 2024-12-09 16:03
 */
@Slf4j
@Aspect
@Component
public class RecordTimeAspect {

    @Around("execution(* com.xju.subjectsystem.service.*.*(..))")
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long startTime = System.currentTimeMillis();

        Object result = joinPoint.proceed();

        long endTime = System.currentTimeMillis();


        log.info("Method {} execution time: {} ms", joinPoint.getSignature(), endTime - startTime);

        return result;
    }
}
